package com.liukai.todo.controller;

import com.liukai.todo.entity.RespBean;
import com.liukai.todo.service.IUserService;
import com.liukai.todo.vo.LoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@Api(tags = "LoginController")
public class LoginController {

    @Autowired
    private IUserService iUserService;

    @GetMapping("/test2")
    public String test2(){
        return "test2";
    }

    @GetMapping("/test")
    public String test(){
        return "test";
    }

    @PostMapping("/login")
    @ApiOperation(value = "登录")
    public RespBean login(@RequestBody LoginVO loginVO, HttpServletRequest request) {
        System.out.println("登录的账号：" + loginVO.getUserName());
        System.out.println("登陆的密码：" + loginVO.getUserPass());
        System.out.println(loginVO);
        return iUserService.login(loginVO.getUserName(), loginVO.getUserPass(), request);
    }

    @GetMapping("/logout")
    @ApiOperation(value = "退出登录")
    public RespBean logout(@RequestBody LoginVO loginVO, HttpServletRequest request){
//        request.getHeader();
        return RespBean.success("logout success");
    }



}
